import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/home',
    meta: { title: '博客首页' },
    name: 'home',
    component: () => import('@/views/BlogHome.vue'),
    children: [
      {
        path: 'main',
        name: 'main',
        meta: { title: '博客首页' },
        component: () => import('@/views/home/HomeMain.vue'),
      },
      {
        path: 'search',
        name: 'search',
        meta: { title: '搜索文章' },
        component: () => import('@/views/home/HomeSearch.vue'),
      },
      {
        path: 'classify',
        name: 'classify',
        meta: { title: '文章分类' },
        component: () => import('@/views/home/HomeClassify.vue'),
      },
      {
        path: 'classifydetalis/:labelName',
        name: 'classifydetalis',
        meta: { title: '分类详情' },
        component: () => import('@/views/home/ClassifyDetails.vue'),
      },
      {
        path: 'about',
        name: 'about',
        meta: { title: '关于' },
        component: () => import('@/views/home/AboutCenter.vue')
      },

      {
        path: '/home',
        redirect: '/home/main'
      }
    ]
  },
  {
    path: '/talk',
    name: 'talk',
    meta: { title: '动态' },
    component: () => import('@/views/home/HomeTalk.vue')
  },
  {
    path: '/detail',
    meta: { title: '博客详情' },
    name: 'details',
    component: () => import('@/views/ArticleDetails.vue')
  },
  {
    path: '/message',
    name: 'meassage',
    meta: { title: '留言板' },
    component: () => import('@/views/home/MeassagePage.vue')
  },
  {
    path: '/',
    redirect: '/home'
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
// 定义全局拦截（守卫）后置全局拦截
router.afterEach((to, from) => { // 每次切换的时候切换标题名字用到了路由元传参
  document.title = to.meta.title || '小赵后台'
})

export default router
